package com.paomi.client.activity.search.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.paomi.client.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by pc on 2018/12/21
 * Describe:
 * com.paomi.client.activity.search.adapter
 */
public class SearchGridAdapter extends RecyclerView.Adapter<SearchGridAdapter.ViewHolder> {
    Context context;
    List<String> mlist = new ArrayList<>();
    OnItemClick onClickListener;
    private Typeface mType;
    public void OnItemClick(OnItemClick onClickListener) {
        this.onClickListener = onClickListener;
    }


    public SearchGridAdapter(Context context, Typeface typeface) {
        this.context = context;
        this.mType = typeface;
    }

    public void setData(List<String> list) {
        this.mlist = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.search_history_item, parent, false));
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        String ticket = mlist.get(position);
        holder.search_tv.setText(ticket);
        holder.search_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener!=null){
                    onClickListener.setOnItemClick(holder.search_tv,position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.search_tv)
        TextView search_tv;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClick {
        void setOnItemClick(View view, int pos);
    }
}
